local insert = function (a_list, value)
	if a_list == nil then
		a_list = {value=value, next=nil}
		return a_list 
	end

	local last = a_list
	while last.next ~= nil do
		last = last.next
	end

	last.next = {value = value, next = nil}
	return a_list
end

local print_list = function (a_list)
	local a_node = a_list
	while a_node ~= nil do
		print(a_node.value)
		a_node = a_node.next
	end
end

local list = insert(nil, 1)
insert(list, 2)
insert(list, 3)
insert(list, 4)
print_list(list)